<?php

namespace App\Http\Controllers\v1;

use App\Model\CardModel;
use App\Model\CommentModel;
use App\Model\SchoolKeepModel;
use App\Model\SchoolModel;
use Illuminate\Http\Request;
use App\Http\Controllers\v1\BaseController;
use Illuminate\Support\Facades\Cache;

class SchoolController extends BaseController
{
    //获取学校
    public function getALLSchool(Request $request){

        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        $res  = ( new  SchoolModel()) ->getALLSchool($uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> success('失败！',$res['data']);
        }

    }

    //搜索学校
    public function searchSchool(Request $request){
       $schoolName =  $request ->get('schoolName');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

       if(empty($schoolName)){
           return $this->error('缺少参数！');
       }

       $res = (new SchoolModel()) ->searchSchool($schoolName,$uuid);

       if($res['code']){
           return $this->success('成功！',$res['data']);
       }else{
           $this->error('失败！',$res['data']);
       }

    }

    /**
     * 统计学校发帖数量
     * @param Request $request
     * @return SchoolController
     */
    public function schoolPostMsg(Request $request){
        $sid=  $request ->get('sid');
        if(empty($sid)){
            return $this->error('缺少参数！');
        }

        $res = (new CommentModel()) ->schoolPostMsg($sid);

        if($res['code']){
            return $this->success('成功！',$res['data']);
        }else{
            $this->error('失败！',$res['data']);
        }

    }

    /**
     * 统计学校关注数量
     * @param Request $request
     * @return SchoolController
     */
    public function schoolFocusNum(Request $request){
        $sid=  $request ->get('sid');//学校id
        if(empty($sid)){
            return $this->error('缺少参数！');
        }

        $res = (new SchoolKeepModel()) ->schoolFocusNum($sid);

        if($res['code']){
            return $this->success('成功！',$res['data']);
        }else{
            $this->error('失败！',$res['data']);
        }
    }

    /**
     * 统计学校关注数量
     * @param Request $request
     * @return SchoolController
     */
    public function schoolCommentNum(Request $request){
        $sid=  $request ->get('sid');//学校id
        if(empty($sid)){
            return $this->error('缺少参数！');
        }

        $res = (new CommentModel()) ->schoolCommentNum($sid);

        if($res['code']){
            return $this->success('成功！',$res['data']);
        }else{
            $this->error('失败！',$res['data']);
        }
    }

    /**
     * 统计学校流量数量
     * @param Request $request
     * @return SchoolController
     */
    public function schoolFlowNum(Request $request){
        $sid=  $request ->get('sid');//学校id

        if(empty($sid)){
            return $this->error('缺少参数！');
        }

        $res = (new CommentModel()) ->schoolFlowNum($sid);

        if($res['code']){
            return $this->success('成功！',$res['data']);
        }else{
            $this->error('失败！',$res['data']);
        }
    }

    /**
     * 学校详细
     * @param Request $request
     * @return SchoolController
     */
    public function schoolDescALL(Request $request){
        $sid = $request ->get('sid');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        $res  = ( new  CardModel()) ->schoolDescALL($sid,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }
    }

    /**
     *  学校详细
     * @param Request $request
     * @return SchoolController
     */
    public function schoolDescNew(Request $request){

        $sid = $request ->get('sid');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        $res  = ( new  CardModel()) ->schoolDescNew($sid,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
            return $this -> error('失败！',$res['data']);
        }
    }

    /**
     *  学校详细
     * @param Request $request
     * @return SchoolController
     */
    public function schoolDescHot(Request $request){
        $sid = $request ->get('sid');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];


        $res  = ( new  CardModel()) ->schoolDescHot($sid,$uuid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
        }
    }

    /**
 *  关注学校
 * @param Request $request
 * @return SchoolController
 */
    public function SaveFocusSchool(Request $request){

        $sid = $request ->get('sid');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($sid) ){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  SchoolKeepModel()) ->SaveFocusSchool($uuid,$sid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
        }
    }

    /**
     *  取消关注学校
     * @param Request $request
     * @return SchoolController
     */
    public function DeletedFocusSchool(Request $request){

        $sid = $request ->get('sid');
        $token = $request ->header('token');
        $uuid =  Cache::get($token)['uuid'];

        if(empty($sid) ){
            return $this ->error('缺少参数！');
        }

        $res  = ( new  SchoolKeepModel()) ->DeletedFocusSchool($uuid,$sid);

        if($res['code']){
            return $this -> success('成功！',$res['data']);
        }else{
        }
    }


}
